﻿using Cache.Aop.Attributes;
using Cache.Aop.Entities;
using Cache.Aop.TestServices;
using Microsoft.AspNetCore.Mvc;

namespace Cache.Aop.Controllers
{

    /// <summary>
    /// 
    /// </summary>
    [ApiController]
    [Route("[controller]")]
    public class AopCacheTestController: ControllerBase
    {
        private readonly IUserService _userService;

        public AopCacheTestController(IUserService userService)
        {
            _userService = userService;
        }

        /// <summary>
        /// 测试aop缓存redis
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetListAsync()
        {
            var response = await _userService.GetListAsync();
            return Ok(response);
        }


        /// <summary>
        /// 测试aop缓存redis
        /// </summary>
        /// <returns></returns>
        [HttpGet("detail")]
        public async Task<IActionResult> GetModelAsync(long id)
        {
            var response = await _userService.GetUserInfoAsync(id);
            return Ok(response);
        }

        /// <summary>
        /// 更新操作
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<IActionResult> UpdateModelAsync(UserInfo user)
        {
            var response = await _userService.UpdateUserAsync(user);
            return Ok(response);
        }

    }
}
